interface PageData{
  inputVisible:boolean,
  dialogChoices:any,
  dialogInput:string
}

interface PageMethods{
  startScaner():void,
  startInputDialog():void,
  onInputDialogConfirmed():void,
  onInputDialogCanceled():void,
  dialogClose():void,
  showToast(content: string):void,
  onTextInput(e: any):void
}

Page<PageData,PageMethods>({
  data: {
    inputVisible: false,
    dialogChoices: {
      buttons: [{ text: '取消', type: 'default' }, { text: '确定', type: 'primary' }],
      layout: 'horizontal'
    },
    dialogInput:''
  },
  onLoad() {},
  startScaner(){
    my.scan({
      success: (res) => {
        my.alert({ content: '扫描成功，结果：' + JSON.stringify(res), });
        //TODO：解析扫码结果
        //TODO: 验证是否为当前用户，如果不是则提示
        //TODO: 解析成功后，调用接口，写入数据
        //TODO: 跳转到验证码页面
      },
      fail: (error) => {
        my.alert({ content: '扫描失败，结果：' + JSON.stringify(error), });
      },
      complete: (res) => {
        my.showToast({ content: 'complete回调！', });
      },
    });
  },
  startInputDialog() {
    this.setData({ ["inputVisible"]: true });
  },
  onInputDialogConfirmed() {
    this.showToast(`点击了确定按钮,输入的值为`+this.data.dialogInput);
    this.dialogClose();
    //TODO: 调用接口获取数据(Loading+提示)
    //TODO：解析返回结果
    //TODO: 验证是否为当前用户，如果不是则提示
    //TODO: 解析成功后，调用接口，写入数据
    //TODO: 跳转到验证码页面
  },
  onInputDialogCanceled() {
    this.showToast(`点击了取消按钮`);
    this.dialogClose();
  },
  dialogClose() {
    this.setData({
      inputVisible: false
    });
  },
  showToast(content) {
    my.showToast({ content, duration: 1000 });
  },
  onTextInput(e){
    this.setData({
      dialogInput: e.detail.value
    });
  }
});
